#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int V = 60000,N = 8005;
int vis[V+5],b[V+5],pr[V+5],tot;
int x[N],y[N],m,n,v[N];
ll ans = 0;
int solve()
{
    ans = 0;
    cin>>n>>m;
    for(int i = 1;i <= n;i++)
        cin>>x[i]>>y[i];
    for(int i = 1;i <= n;i++) cin>>v[i];
    for(int i = 1;i <= n;i++)
    {
        for(int j = i+1;j <= n;j++)
        {
            for(int k = j+1;k <= n;k++)
            {
                int d1 = abs(x[j]-x[k]) + abs(y[j]-y[k]);
                int d2 = abs(x[j]-x[i]) + abs(y[j]-y[i]);
                int d3 = abs(x[i]-x[k]) + abs(y[i]-y[k]);
                int D = d1 + d2 + d3 - max(max(d2,d3),d1) - min(min(d2,d3),d1);
                if(b[D] && (D%20 == 3 || D <= 10)) ans += v[i] + v[j] + v[k];
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}
int main()
{
    freopen("chess.in","r",stdin);
    freopen("chess.out","w",stdout);
    ios::sync_with_stdio(false);cin.tie(0);
    int T;cin>>T;
    for(int i = 2;i <= V;i++)
    {
        if(!vis[i]) vis[i] = pr[++tot] = i,b[i] = 1;
        for(int j = 1;j <= tot && pr[j] <= vis[i] && pr[j]*i <= V;j++)
            vis[pr[j]*i] = pr[j];
    }
    while(T--) solve();
    return 0;
}